1 <?php
2 session_start();
3
4 include_once(
'includes/config.php');
5 $url =
"http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
6 $product_name_url = substr($url, strpos($url,
'?') + 1);
7
8 if
(!empty($product_name_url)) {
9     
10     $getProduct = $db_conn -> prepare(
"SELECT * FROM products WHERE product_url = '$product_name_url'");
11     $getProduct -> execute();
12     $product = $getProduct -> fetch(PDO::FETCH_ASSOC);
13
14     $product_id_next = $product[
'product_id'] + 1;
15     $product_id_prev = $product[
'product_id'] - 1;
16
17     $nextProduct = $db_conn -> prepare(
"SELECT product_url FROM products WHERE product_id = '$product_id_next'");
18     $nextProduct -> execute();
19     $next_product = $nextProduct -> fetch();
20
21     $prevProduct = $db_conn -> prepare(
"SELECT product_url FROM products WHERE product_id = '$product_id_prev'");
22     $prevProduct -> execute();
23     $prev_product = $prevProduct -> fetch();
24
25     $rows = $getProduct -> rowCount();
26     
if ($rows > 0) {
27         # Product exists
28     }
else {
29         header(
"Location: index.php");
30     }
31 }
else {
32     header(
"Location: index.php");
33 }
34
35 #Auth Section

36 if
(isset($_SESSION['email']) && isset($_SESSION['token'])) {
37
38     #Store retrieved session values
39     $email = $_SESSION[
'email'];
40     $token = $_SESSION[
'token'];
41
42     #
if email and token is set check them against the database, retrieve and store the email and token retrieved for comparison
43
44     $sql =
"SELECT user_email, user_token from users WHERE user_email = '$email'";
45     $retrieveStmt = $db_conn -> prepare($sql);
46     $retrieveStmt -> execute();
47
48     $user_row = $retrieveStmt -> fetch(PDO::FETCH_ASSOC);
49
50     
if ($user_row > 0) {
51         # store values to be compared
52         $_server_email = $user_row[
'user_email'];
53         $_server_token = $user_row[
'user_token'];
54     }
55
56 }
57
58 $totalCartProducts =
0;
59
60 if
(isset($_SESSION['email'])) {
61     
// Check if product is in user cart
62     $arr = explode(
"@", $_SESSION['email'], 2);
63     $cartName = $arr[
0] . '_cart';
64
65     $productInCartID = $product[
'product_id'];
66     $checkCart = $db_conn -> prepare(
"SELECT * FROM $cartName WHERE product_id = $productInCartID");
67
68     $checkCart -> execute();
69     $checkCartProduct = $checkCart -> fetch(PDO::FETCH_ASSOC);
70
71     $allUserCartProductss = $db_conn -> prepare(
"SELECT * FROM $cartName");
72     $allUserCartProductss -> execute();
73
74     $totalCartProducts = $allUserCartProductss -> rowCount();
75 }
76
77
78 ?>
79
80 <!DOCTYPE html>
81 <html>
82 <head>
83     <meta charset=
"utf-8" />
84     <meta http-equiv=
"X-UA-Compatible" content="IE=edge">
85     <title>MSwiss | <?php echo $product[
'product_name'] ?></title>
86     <meta name=
"viewport" content="width=device-width, initial-scale=1">
87
88     <!-- Favicons -->
89     <link rel=
"icon" type="image/png" href="images/icons/favicon-32x32.png" sizes="32x32" />
90     <link rel=
"icon" type="image/png" href="images/icons/favicon-128.png" sizes="128x128" />
91     
92     <!-- Main CSS-->
93     <link rel=
"stylesheet" type="text/css" media="screen" href="css/main.css" />
94
95     <!-- Products CSS -->
96     <link rel=
"stylesheet" type="text/css" media="screen" href="css/products.css" />
97
98     <!-- Product Detail CSS -->
99     <link rel=
"stylesheet" type="text/css" media="screen" href="css/product-detail.css" />
100
101     <!-- Anonymous Pro Font CDN -->
102     <link href=
"https://fonts.googleapis.com/css?family=Anonymous+Pro" rel="stylesheet">
103
104     <!-- Owl Carousel CDN -->
105     <link rel=
"stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
106     
107     <!-- Owl Carousel Theme CDN -->
108     <link rel=
"stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css">
109
110 </head>
111 <body>
112
113     <div
class="side-menu">
114     <ul>
115         <li>
116             <a href=
"index.php">
117                 Home
118             </a>
119         </li>
120         <li>
121             <a href=
"products.php" class="active-link">
122                 Shop
123             </a>
124         </li>
125         <li>
126             <a href=
"index.php">
127                 About
128             </a>
129         </li>
130         <li>
131             <a href=
"cart.php">
132                 Cart
133             </a>
134         </li>
135         <li>
136             <a href=
"index.php">
137                 Contact
138             </a>
139         </li>
140     </ul>
141
142     <a href=
"#" class="disclaimer">Privacy Policy</a>
143     <a href=
"#" class="disclaimer">Disclaimer</a>
144     </div>
145
146     <div
class="clearfix"></div>
147
148     <div
class="overlay">
149
150     </div>
151
152     <div
class="clearfix"></div>
153
154     <div
class="login-wrapper">
155         <h3>Login</h3>
156         <form id=
"login-form">
157             <input type=
"email" id="login-email" name="login-email" placeholder="Email Address" required/>
158             <input type=
"password" id="login-password" name="login-password" placeholder="Password" required/>
159             <p></p>
160             <input id=
"login-btn" type="submit" value="Log in" />
161         </form>
162     </div>
163
164     <div
class="signup-wrapper">
165         <h3>Sign up</h3>
166         <form id=
"signup-form">
167             <input type=
"text" id="signup-name" placeholder="Name*" required/>
168             <input type=
"email" id="signup-email" placeholder="Email Address*" required/>
169             <input type=
"password" id="signup-password" placeholder="Password*" required/>
170             <input type=
"text" id="signup-address" placeholder="Address*" required/>
171             <p></p>
172             <input id=
"signup-btn" type="submit" value="Sign up" />
173         </form>
174     </div>
175     
176     <div
class="container">
177
178         <nav>
179             <div
class="menu-container">
180                 <div
class="menu-icon">
181                     <span
class="menu-aria"></span>
182                     <span
class="menu-aria"></span>
183                     <span
class="menu-aria"></span>
184                     <div
class="menu-text">
185                         <p>Menu</p>
186                     </div>
187                 </div>
188                 <div
class="menu-login-signup">
189                 <?php
190                     
if (isset($_SESSION['email']) && isset($_SESSION['token'])) {
191                         
if ($email == $_server_email && $token == $_server_token)
192                         {
193                             echo
'<a href="includes/logout.php" class="user-logout">Logout</a>';
194                         }
195                     }
else {
196                         echo
'<a href="#" class="login">Login</a>
197                         <a href=
"#" class="signup">Signup</a>';
198                     }
199                     ?>
200                 </div>
201                 <div
class="menu-cart">
202                     <div
class="cart-count">
203                         <p><?php echo $totalCartProducts; ?></p>
204                     </div>
205                     <p>
206                         <?php
207
208                         
if (isset($_SESSION['email']) && isset($_SESSION['token'])) {
209                             echo
'<a href="cart.php">Cart</a>';
210                         }
else {
211                             echo
'Cart';
212                         }
213                         ?>
214                     </p>
215                 </div>
216             </div>
217         </nav>
218
219         <div
class="product-container">
220             <div
class="owl-carousel">
221                 <div
class="product-image item">
222                     <img src=
"<?php echo $product['product_image_1']; ?>" alt="Product 1" />
223                 </div>
224                 <div
class="product-image item">
225                     <img src=
"<?php echo $product['product_image_2']; ?>" alt="Product 1" />
226                 </div>
227                 <div
class="product-image item">
228                     <img src=
"<?php echo $product['product_image_3']; ?>" alt="Product 1" />
229                 </div>
230             </div>
231
232             <div
class="product-title">
233                 <h4><?php echo $product[
'product_name']; ?></h4>
234                 <p>$<?php echo $product[
'product_price']; ?></p>
235             </div>
236
237             <div
class="product-description">
238                 <div
class="product-description-wrapper">
239                     <p><?php echo $product[
'product_description']; ?></p>
240                     <?php
241                     
if (isset($_SESSION['email']) && isset($_SESSION['token'])) {
242                         
if ($email == $_server_email && $token == $_server_token && $checkCartProduct > 0)
243                         {
244                             
// Show remove from cart button
245                             echo
'
246                             <a
class="add-to-cart added"><span></span></a>
247                             
';
248                         }
else {
249
250                             
// Show add to cart button
251                             echo
'
252                             <a
class="add-to-cart"><span></span></a>
253                             
';
254                         }
255                     }
else {
256                         
// Show add to cart button which redirects to login
257                         echo
'<button class="product-detail-add-to-cart"><span>+</span>Add to cart</button>';
258                     }
259                     ?>
260                 </div>
261             </div>
262
263             <div
class="product-switch">
264                 <?php
265                     
if ($prev_product > 0) {
266                         echo
'<a href="product-detail.php?' . $prev_product['product_url'] . '">
267                         <img
class="previous-button" src="images/icons/icon_previous.png" alt="Previous Product">
268                         </a>
';
269                     }
270
271                     
if ($next_product > 0) {
272                         echo
'<a href="product-detail.php?' . $next_product['product_url'] . '">
273                         <img
class="next-button" src="images/icons/icon_next.png" alt="Next Product">
274                         </a>
';
275                     }
276                 ?>
277                 
278             </div>
279
280             <div
class="clearfix"></div>
281
282         </div>
283     </div>
284
285
286     <!-- jQuery CDN -->
287     <script src=
"https://code.jquery.com/jquery-3.3.1.min.js"></script>
288
289     <!-- Owl Carousel JS -->
290     <script src=
"https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
291
292     <!-- Owl Carousel Thumbs JS -->
293     <script src=
"js/owl.carousel2.thumbs.js"></script>
294
295     <!-- Custom JS -->
296     <script src=
"js/product-detail.js"></script>
297
298     <!-- Custom JS -->
299     <script src=
"js/main.js"></script>
300 </body>
301 </html>


Gõ tìm kiếm nhanh...